package mua.core.value;

import java.util.ArrayList;
import java.util.Arrays;

import static mua.core.interpreter.Util.*;


/**
 * 列表类型，注意未实现列表中包含列表的功能！！！p4阶段需修改！！！
 */
public class List extends MuaValue {
    public List(){
        super();
        value = "";
    }

    public List(String str){
        super();
        ArrayList<MuaValue> list = new ArrayList<>();
        if(!str.equals("[]")){
            String temp = myTrim(str).substring(1,str.length()-1);
            String[] parts = split(temp);
            while(parts[0]!=null&&!parts[0].isEmpty()){
                list.add(judgeType(parts[0]));
                parts = split(parts[1]);
            }
//            String temp = myTrim(str).substring(1,str.length()-1);
//            String[] parts = temp.split(" ");
//            for(String part:parts){
//                list.add(new Word(part));
//            }
        }
        value = list;
    }

    public List(ArrayList<MuaValue> list){
        value = list;
    }

    public List(MuaValue a, MuaValue b){
        value = Arrays.asList(a,b);
    }

    public int size(){
        return ((List)value).size();
    }
}
